// useFetchUserInfo.js
import { useDispatch, useSelector } from "react-redux";
import { setToken } from "@/store/modules/global";
import { storage } from "@/utils/Storage";

const useToken = () => {
	const dispatch = useDispatch();
	// @ts-ignore
	const token = useSelector(state => state.global.token);
	const pushToken = (token: string) => {
		storage.setCookie(import.meta.env.VITE_GLOB_TOKEN_KEY, token);
		dispatch(setToken(token));
	};
	const clearToken = () => {
		storage.removeCookie(import.meta.env.VITE_GLOB_TOKEN_KEY);
		dispatch(setToken(""));
	};
	return { token, pushToken, clearToken };
};

export default useToken;
